# -*- coding: utf-8 -*-
# @Time : 2023/10/25 15:16
# @Author : ZH
# @File : 13.py
# @Software: PyCharm
class Solution:

    def __init__(self):
        self.base_data = {
            "I": 1,
            "V": 5,
            "X": 10,
            "L": 50,
            "C": 100,
            "D": 500,
            "M": 1000
        }

    def romanToInt(self, s: str) -> int:
        # IIIVL
        s = s[::-1]
        e_num = 0
        for index, value in enumerate(s):
            if index > 0:
                if self.base_data[s[index]] < self.base_data[s[index - 1]]:
                    e_num -= self.base_data[s[index]]
                else:
                    e_num += self.base_data[s[index]]
            else:
                e_num += self.base_data[s[index]]

        return e_num


if __name__ == '__main__':
    so = Solution()
    l = so.romanToInt('MCMXCIV')
    print(l)
